package com.graduation.lastproject.service.admin.AdminHighActive.impl;

import com.graduation.lastproject.dao.admin.AdminHighDao;
import com.graduation.lastproject.entity.*;
import com.graduation.lastproject.service.admin.AdminHighActive.AdminHighService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class IAdminHighService implements AdminHighService {
    @Autowired
    private AdminHighDao adminHighDao;

    public IAdminHighService() {
        super();
    }

    @Override
    public Integer getTotal(User user) {
        return adminHighDao.getTotal(user);
    }

    @Override
    public List<User> getUserListPage(User user) {
        return adminHighDao.getUserListPage(user);
    }

    @Override
    public int updataUserInfo(Map<String, Object> map) {
        return adminHighDao.updataUserInfo(map);
    }

    @Override
    public Integer getBusinessTotal(Business business) {
        return adminHighDao.getBusinessTotal(business);
    }

    @Override
    public List<Business> getBusinessListPage(Business business) {
        return adminHighDao.getBusinessListPage(business);
    }

    @Override
    public int updataBusinessInfo(Map<String, Object> map) {
        return adminHighDao.updataBusinessInfo(map);
    }

    @Override
    public Integer getBusinessInfoTotal(HotelInfo hotelInfo) {
        return adminHighDao.getBusinessInfoTotal(hotelInfo);
    }

    @Override
    public List<HotelInfo> getBusinessInfoListPage(HotelInfo hotelInfo) {
        return adminHighDao.getBusinessInfoListPage(hotelInfo);
    }

    @Override
    public int passHotel(String id) {
        return adminHighDao.passHotel(id);
    }

    @Override
    public int returnHotel(Map<String, Object> map) {
        return adminHighDao.returnHotel(map);
    }

    @Override
    public int getOrderTotal(Bookorder bookorder) {
        return adminHighDao.getOrderTotal(bookorder);
    }

    @Override
    public List<Bookorder> getOrderInfoListPage(Bookorder bookorder) {
        return adminHighDao.getOrderInfoListPage(bookorder);
    }

    @Override
    public int deleteBookorderById(String id) {
        return adminHighDao.deleteBookorderById(id);
    }

    @Override
    public int getReviewTotal(Review review) {
        return adminHighDao.getReviewTotal(review);
    }

    @Override
    public List<Review> getReviewInfoListPage(Review review) {
        return adminHighDao.getReviewListPage(review);
    }

    @Override
    public int deleteReviewById(String reviewId) {
        return adminHighDao.deleteReviewById(reviewId);
    }

    @Override
    public int insertComInfo(Map<String, Object> info) {
        return adminHighDao.insertComInfo(info);
    }

    @Override
    public int getComTotal(Commodity commodity) {
        return adminHighDao.getComTotal(commodity);
    }

    @Override
    public List<Commodity> getComInfoListPage(Commodity commodity) {
        return adminHighDao.getComListPage(commodity);
    }

    @Override
    public int updataExchangeInfo(Map<String, Object> map) {
        return adminHighDao.updataExchangeInfo(map);
    }

    @Override
    public int getShoporderTotal(Commodityorder commodityorder) {
        return adminHighDao.getShoporderTotal(commodityorder);
    }

    @Override
    public List<Commodityorder> getShopInfoList(Commodityorder commodityorder) {
        return adminHighDao.getShopInfoList(commodityorder);
    }

    @Override
    public int deleteIntegralorder(String commodity_orderId) {
        return adminHighDao.deleteIntegralorder(commodity_orderId);
    }

    @Override
    public Map<String, Object> getBooknum() {
        return adminHighDao.getBooknum();
    }

    @Override
    public Map<String, Object> getBookPrice() {
        return adminHighDao.getBookprice();
    }

    @Override
    public int getHotelpriceTotal(Hotelincome hotelincome) throws ParseException {
        String subTime="";
       /*比较 2020-03 与 2020-04  而不是 2020-02 与 2020-03*/
        if(hotelincome.getInTime()!=null && hotelincome.getInTime()!=""){
             subTime=subMonth(hotelincome.getInTime());
        }
        hotelincome.setInTimeAdd(subTime);
        return adminHighDao.getHotelpriceTotal(hotelincome);
    }

    @Override
    public List<Hotelincome> getHotelpriceInfo(Hotelincome hotelincome) throws ParseException {
        String subTime="";
        /*比较 2020-03 与 2020-04  而不是 2020-02 与 2020-03*/
        if(hotelincome.getInTime()!=null && hotelincome.getInTime()!=""){
            subTime=subMonth(hotelincome.getInTime());
        }
        hotelincome.setInTimeAdd(subTime);
        return adminHighDao.getHotelpriceInfo(hotelincome);
    }

    @Override
    public Map<String,Object> getHotelpriceInfoExport(String inTime) throws ParseException {
        String subTime="";
        String redTime="";
        if(inTime!=""){
            subTime=subMonth(inTime);
            redTime=inTime;
        }
        List<Map<String,Object>> result =adminHighDao.getHotelpriceInfoExport(redTime,subTime);
        Map<String, Object> map = new HashMap<>();
        String[] hotelNameArr=new String[result.size()];
        String[] hotelPriceArr = new String[result.size()];
        String[] hotelZfbArr = new String[result.size()];
        for (int i = 0; i < result.size(); i++) {
            Map<String,Object> map1 = result.get(i);
            hotelPriceArr[i] = map1.get("hotelPrice") == null ? "0" : map1.get("hotelPrice").toString();
            hotelNameArr[i] = map1.get("hotelName") == null ? "0" : map1.get("hotelName").toString();
            hotelZfbArr[i] = map1.get("bzfbcard") == null ? "未拥有" : map1.get("bzfbcard").toString();
        }
        map.put("hotelNameArr",hotelNameArr);
        map.put("hotelPriceArr", hotelPriceArr);
        map.put("hotelZfbArr", hotelZfbArr);
        return map;
    }

    @Override
    public int deleteComById(String deleteComId) {
        return adminHighDao.deleteComById(deleteComId);
    }

    /****
     * 传入具体日期 ，返回具体日期增加一个月。
     */
    private  String subMonth(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date dt = sdf.parse(date);               //解析字符串的文本，生成 Date。
        Calendar rightNow = Calendar.getInstance();   //返回对象
        rightNow.setTime(dt);                      //设置日历字段 YEAR、MONTH 和 DAY_OF_MONTH 的值
        rightNow.add(Calendar.MONTH, 1);  //日期类日期操作
        Date dt1 = rightNow.getTime();             //返回一个表示此 Calendar 时间值（从历元至现在的毫秒偏移量）的 Date 对象。
        String reStr = sdf.format(dt1);           // 将给定的 Date 格式化为日期/时间字符串
        return reStr;
    }

    /****
     * 传入具体日期 ，返回具体日期减少一个月。
     */
    private  String redMonth(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date dt = sdf.parse(date);               //解析字符串的文本，生成 Date。
        Calendar rightNow = Calendar.getInstance();   //返回对象
        rightNow.setTime(dt);                      //设置日历字段 YEAR、MONTH 和 DAY_OF_MONTH 的值
        rightNow.add(Calendar.MONTH, -1);  //日期类日期操作
        Date dt1 = rightNow.getTime();             //返回一个表示此 Calendar 时间值（从历元至现在的毫秒偏移量）的 Date 对象。
        String reStr = sdf.format(dt1);           // 将给定的 Date 格式化为日期/时间字符串
        return reStr;
    }
}
